home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Pointer to non-static method
- Date: Wed, 17 Apr 1996 00:27:08 -0400
- Organization: Datalytics, Inc.
- Message-ID: <3174731C.4B7B@datalytics.com>
- References: <Dpn2MG.9y0@oce.nl> <316E4C6F.3738@Athene.co.uk>
- NNTP-Posting-Host: 204.62.224.241
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- C.J. Scaife wrote:
- >
- > Emile Heyns wrote:
- > >
- > > Hi all,
- > >
- > > I am looking for a way to store and use a pointer to a method. I will
- > > be using this pointer from within another method of the same object
- > > (I will remain "within" the object). So far, I have been using thus
- > > kludge:
- > >[snip]
- > >
- > > but this will limit me to instantiating only one object of this class.
- > > Any ideas?
- > >[snip]
- >
- > Here is something I wrote some years ago. I think it does exactly what
- > you want. The cs_state class can be inherited to give this method
- > pointer facility to more complex derived classes. Let me know if you
- > need help with it :)
- >
-
- What he really needs is a pointer to a member function. The
- syntax is little different from a "normal" function pointer:
-
- typedef return_type (class_name::* type_name)(parameter_list);
-
- This can be declared within the class declaration. Now declare
- a dm of that type:
-
- type_name m_Method;
-
- To invoke the function currently assigned to the pointer, use
- this syntax:
-
- (this->*m_Method)(parameters);
-
- --
- Rob Stewart | My opinions are generally my own. They do
- Datalytics, Inc.| not necessarily reflect those of my employer.
-